<!--#INCLUDE FILE="config.asp"-->
<%
if(Session("AdminAccessLevel") <> 1 and Session("AdminAccessLevel") <> 3) then
	Response.Redirect("admin-login.asp?msg=invalid")
end if

if (Request("gId") <> "") then
	guestId = Request("gId")
	letterFile = Request("letterPrefix")

	sqlstring = "SELECT * FROM Guests WHERE GuestID = "&guestId
	
	set objConnect1 = server.createObject("ADODB.Connection")   

	objConnect1.Open conStr

	set TblTemp1 = server.createobject("Adodb.Recordset")
		
		TblTemp1.Open sqlstring, objConnect1
		
	If not TblTemp1.EOF then
		Email = TblTemp1("Email")
		FirstN = TblTemp1("Name")
		LastN = TblTemp1("Surname")
	end if
end if


%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../styles.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<!-- DATE PICKER SCRIPT -->
<link type="text/css" href="../css/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.21.custom.min.js"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
    $('#list_table tr:nth-child(2n+1)').addClass('alternate');
	var name, x;
	name = "";
	if ($('#sendmail'))
		$('#sendmail').click(function(){
			$.ajax({
				type:"POST",
				url: "SendMailReservationProcess.asp",
				dataType: "html",
				data: {emailto:$("#Emailto").val(), subject:$("#subject").val(), content:$("#EmailContent").val(), guestid:$("#guestid").val(),letterPrefix:$("#letter").val(),nameGuest:$("#Fullname").val(),attach: name},
				async: false,
				success: function(data){ 
					$('#error').html(data);
				}
			});
			return false;
		});
		
		// upload files
		$("#upload").click(function() {
			$("#info").html('<p>uploading...</p>');
			var length = $("#pdf").attr("files").length;
			x = 0;
			for (i = 0; i < length; i++){
				var file_data = $("#pdf").attr("files")[i];   // Getting the properties of file from file field	
				var form_data = new FormData();                  // Creating object of FormData class				
				form_data.append("file", file_data);              // Appending parameter named file with properties of file_field to form_data
			
				$.ajax({
					url: "upload.asp",
					dataType: 'script',
					cache: false,
					contentType: false,
					processData: false,
					data: form_data,                         // Setting the data attribute of ajax with file_data
					type: 'post',
					async: false,
					success: function(data){ 
						x = x + 1;
						name += data + ";";
					}
				});
				
			}
			if (x == length) {
				$("#info").html('<p>Uploaded Successfully!</p>');
			} else {
				$("#info").html('<p>Error!</p>');
			}
			return false;
		});
		
		//Created an array to hold onto the desired info.
		var windowSizeArray = [ "width=800,height=600",
                            "width=800,height=600,scrollbars=yes"];
 
        //Links that has the ".newWindow" class will call this script.
        $('#downloadPdf').click(function (event){
 
            // Gets the URL from the clicked link.
            var url = 'DownloadPdfFile.asp?letterPrefix='+$("#letter").val();
 
            /*Gets the name from the clicked link. Currently I commented out the
              jquery script and just put "popUp" for a default name because I didn't
              include the name in the links.*/
            var windowName = "Download PDF File";//$(this).attr("name");
 
            /*Places the string from the array into the windowSize variable.
              The array slot is determined by the "rel" number on the link.*/
            var windowSize = windowSizeArray[1];
 
            //This method opens a new browser window.
            window.open(url, windowName, windowSize);
 
            /*Prevents the browser from executing the default action and
              allows us to use the "window.open" within our script.*/
            event.preventDefault();
 
        });
});
</script>

  

<title>Admin Extender Campaña :: Costa Baja</title>

</head>
<body>

<div id="main_wrapper">
    	<div class="main_wrapper_margin">
        	
            <div class="admin_top_menu">
            <!--#INCLUDE FILE="admin_menu.asp"--> 
           	</div><!-- END admin_top_menu -->
             
			<h1>Email Reservation</h1>
            <div class="clear"></div>
               <hr/>
            <div class="dashboad_wrapper">
       <form id="extend">
			 <table cellpadding="0" width="100%">
				<tr>
					<td width="33%">
            		<label>Subject: </label><br />
					<input type="text" name="subject" id="subject" value=""/>
  					</td>
				</tr>
				<tr>
					<td width="33%">
            		<label>To: </label><br />
					<input type="text" name="Fullname" id="Fullname" value="<%=LastN%> <%=FirstN%> "/>
  					</td>
				</tr>
				<tr>
					<td width="33%">
            		<label>Email: </label><br />
					<input type="text" name="Emailto" id="Emailto" value="<%=Email%>"/>
  					</td>
				</tr>
				<tr>
					<td width="33%">
            		<label>Content Email: </label><br />
					<textarea cols="40" rows="5" name="EmailContent" id="EmailContent">You reservation has been approved, below please find your reservation number(s) and the confirmed dates of your stay. We will be following up with you to get your travel details and to see if you need transportation once you arrive.
						Thank you,
						CostaBaja
					</textarea>
  					</td>
				</tr>
				<tr>
					<td>
					<label>Upload your pdf to attach email</label>
						<form method="post" enctype="multipart/form-data"  action="">
							<input type="file" name="pdf" id="pdf" multiple />
							<button type="button" id="upload">Upload Files!</button>
						</form>
					</td>
					
				</tr>
				<tr>
				<td>
					<span id="info"></span>
					</td>
				</tr>
				<tr>
				<td>
					<input type="hidden" name="guestid" id="guestid" value="<%=guestId%>"/>
	
					<input type="button"  value="Enviar" id="sendmail"/>
				</td>
				<td>
					
					<input type="hidden" name="letter" id="letter" value="<%=letterFile%>"/>
					<input type="button"  value="Letter" id="downloadPdf"/>
				</td>
				</tr>
            
			 </table>
       </form>      
 <span id ="error"></span>
            </div><!-- .dashboad_wrapper -->
                        
    	</div><!-- END .main_wrapper_margin -->
        
	</div><!-- END #main_wrapper -->

         <!-- FOOTER -->
         
         <!--#INCLUDE file="admin_footer.asp"-->
         
         <!-- END FOOTER -->   

</body>
</html>
